﻿$(document).ready(function () {
    $("#slider_holder").bindSlider();
    $.each($("#banner_holder .td-banner"), function () {
        $(this).bindBanner();
    })
    
});

$.fn.extend({
    bindSlider: function () {
        var container = $(this[0]);
        
        setInterval(function () {
            var current = container.find("img:visible");
            current.fadeOut(function () {
                if (current.next().length) {
                    current.next().fadeIn();
                } else {
                    container.find("img:first").fadeIn();
                }
            });
        },3000);
    },
    
    bindBanner: function () {
        var container = $(this[0]);
        
        container.mouseenter(function () {
            container.addClass("td-banner-hover");
            container.find(".btn-view").show();
        })
        .mouseleave(function () {
            container.removeClass("td-banner-hover");
            container.find(".btn-view").hide();
        })
        .click(function () {
            createDetailDialog(container.find(".banner").attr("postpath"));
        });
    }
});